﻿using SpiderStudy.Utils.Currency.FileUtils;
using SpiderStudy.Utils.Helper;
using System.Collections.Generic;

namespace SpiderStudy.WebSite.Edit
{
    internal class EditHelper
    {
        private string excludeWords = StaticValue.BinPath + "EditExclude.txt";
        private List<string> excluedeList = FileHelper.ReadAllLine(new EditHelper().ExcludeWordsPath);

        public List<string> ExcluedeWordList { get => excluedeList; set => excluedeList = value; }
        public string ExcludeWordsPath { get => excludeWords; set => excludeWords = value; }

        /// <summary>
        /// 添加黑名单关键词
        /// </summary>
        /// <param name="ExcludeKey"></param>
        public void AddExcludeKey(string ExcludeKey)
        {
            if (ExcludeKey == "")
                return;
            ExcluedeWordList.Add(ExcludeKey);
            FileHelper.AppendUTF8Text(ExcludeWordsPath, ExcludeKey);
        }

        /// <summary>
        /// 清理列表，并且增加关键词
        /// </summary>
        /// <param name="TextList"></param>
        /// <param name="NewExcludeWords"></param>
        /// <returns></returns>
        public List<string> ListClear(List<string> TextList, string NewExcludeWords)
        {
            AddExcludeKey(NewExcludeWords);
            return ListClear(TextList);
        }

        /// <summary>
        /// 列表清理
        /// </summary>
        /// <param name="TextList"></param>
        /// <param name="ExcluedeList"></param>
        /// <returns></returns>
        public List<string> ListClear(List<string> TextList)
        {
            List<string> TempList = new List<string>();
            foreach (string Text in TextList)
            {
                foreach (string line in ExcluedeWordList)
                {
                    if (Text.IndexOf(line) >= 0)
                        continue;
                }
                TempList.Add(Text);
            }
            return TextList;
        }
    }
}